<template>
  <div class="shangpinDialog">
    <el-dialog
      title="选择采购单号"
      :close-on-click-modal="false"
      :visible.sync="dialogTableVisible"
      width="60%">
      <div class="pageTop" style="padding: 10px 10px;display: flex;align-items: center;height: 50px" >
        <input style="width: 200px;margin-right: 10px" class="inputClass" v-model="queryParams.procurementCode" type="text"  placeholder="请输入采购单号"    v-on:keyup.enter="getList" >
        <el-button type="primary" size="medium" @click="getList">搜 索</el-button>
      </div>
      <el-table
        highlight-current-row
        max-height="300"
        @row-click="rowClick"
        v-loading="loading"
        :data="dataList"
        stripe border style="margin-top: 20px"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}">
        <el-table-column  width="35">
          <template slot-scope="scope">
            <el-radio :label="scope.row.procurementId" v-model="radioId">&nbsp;</el-radio>
          </template>
        </el-table-column>
        <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
        <el-table-column align="center" label="采购单"   property="procurementCode"  width="180" ></el-table-column>
        <el-table-column align="center" label="采购单名称"   property="procurementName"  width="180" ></el-table-column>
        <el-table-column align="center" label="供应商"   property="supplierName"   ></el-table-column>
        <el-table-column align="center" label="采购人员"   property="proUserName"   ></el-table-column>
        <el-table-column align="center" label="仓库"   property="warehouseName"   ></el-table-column>
        <el-table-column align="center" label="备注"   property="remark"  show-overflow-tooltip ></el-table-column>
      </el-table>
      <el-pagination
        style="margin-top: 20px;text-align: right"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30, 40]"
        :current-page="queryParams.current"
        :page-size="queryParams.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>

      <div class="pageTop" style="padding:10px;margin-top: 15px;text-align: right">
        <el-button type="primary" size="medium" @click="determine" >确 定</el-button>
        <el-button  size="medium" @click="cancel" >关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  props: ['cgdData'],
  name: "Role",
  data() {
    return {
      total:0,
      radioId:'',
      warehouseId:'',
      ckname:'',
      codeName:'',
      loading:false,
      // 部门树选项
      deptOptions: undefined,
      defaultProps: {
        children: "child",
        label: "catName"
      },
      dataList:[],
      dialogTableVisible:true,
      queryParams:{
        current:1,
        size:10,
        procurementCode:'',
      },
      multipleSelection:[],
      procurementCount:'',
      procurementMoney:'',
    };
  },
  watch: {
    dialogTableVisible: function () {
      this.dialogTableVisible = true;//始终让他为true;
      this.cancel();//隐藏
    },
  },
  created() {
    console.log('接受',this.cgdData)
    //分类查询
    this.getFenlei()

  },
  mounted() {

  },
  methods: {
    //分类查询
    getFenlei:function (){
      request({
        url: '/wh/products/categoryList',
        method: 'get',
      }).then(response => {
        this.deptOptions =response.data
        this.getList();
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      console.log('节点单击',data.catId)
      this.queryParams.catId = data.catId
      this.getList();
    },
    rowClick(row){
      this.radioId=row.procurementId;
      this.ckname=row.warehouseName
      this.codeName = row.procurementCode
      this.warehouseId = row.warehouseId
      this.procurementCount = row.procurementCount
      this.procurementMoney = row.procurementMoney

      console.log('单选',row)
    },
    //分页查询
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.queryParams.current = val
      this.getList()
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.queryParams.size = val
      this.getList()
    },
    //搜索
    getList:function (){
      this.loading=true
      request({
        url: '/wh/procurement/listBycodeOrName',
        method: 'get',
        params:this.queryParams
      }).then(response => {
        this.loading=false
        if(response.code=='200'){
          this.dataList = response.data.records
          this.total =response.data.total
        }else {
          this.dataList=[]
          this.$message({
            type: 'warning',
            message:response.msg
          });
        }
      });

    },
    //确定
    determine:function(){
      var obj={}
      obj.radioId =  this.radioId
      obj.ckname =  this.ckname
      obj.codeName =  this.codeName
      obj.warehouseId =  this.warehouseId
      obj.procurementCount =  this.procurementCount
      obj.procurementMoney =  this.procurementMoney

      this.$emit('callback',obj)//将submitModel的值传给父组件
    },
    //隐藏
    cancel:function(){
      // this.determine()
      this.$emit('callback','')//将submitModel的值传给父组件
    },

  }
};
</script>
<style scoped>
.shangpinDialog {

}



</style>
